﻿using System.Collections;


public enum LanguageType : int
{
    CN = 0,
    EN = 1,
    TC = 2,//繁体中文
}

public partial class Localization
{
    /// 获取系统语言类型
    /// 不在支持范围内的使用EN
    public static LanguageType systemLanguage
    {
        get
        {
#if !NETCOREAPP
            UnityEngine.SystemLanguage lang = UnityEngine.Application.systemLanguage;
            
            if (lang == UnityEngine.SystemLanguage.Chinese ||
                lang == UnityEngine.SystemLanguage.ChineseSimplified
            )
            {
                return LanguageType.CN;
            }

            if (lang == UnityEngine.SystemLanguage.ChineseTraditional)
            {
                return LanguageType.TC;
            }
#endif          

            return LanguageType.EN;
        }
    }

    private const string LanguageType_Key = "LanguageType_Key";

    /// 当前的语言
    /// 如果没有设定，则使用系统语言
    /// 有设定，则使用设定的语言
    public static LanguageType language
    {
        get
        {
#if EN
            return LanguageType.EN;
#endif

#if !NETCOREAPP
            string lang = UnityEngine.PlayerPrefs.GetString(LanguageType_Key, "");
            if (string.IsNullOrEmpty(lang))
            {
                return Localization.systemLanguage;
            }

            LanguageType langType;

            if (System.Enum.TryParse<LanguageType>(lang, out langType))
            {
                return langType;
            }
#endif

            return Localization.systemLanguage;
        }
        set
        {
#if !NETCOREAPP
            UnityEngine.PlayerPrefs.SetString(LanguageType_Key, value.ToString());
#endif
        }
    }

}
